package com.cssnj.portal.service.query;

import com.cssnj.portal.domain.common.UserInfo;
import com.cssnj.portal.utils.PortalUntil;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.service.base.BaseService;
import io.predictech.framework.utility.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Arthur
 * @version 1.0
 * @description 网上办税情况汇总 开业登记（户数）、税种认定（户次）、发票供票资格认定（户次）、正常申报（户次）等16项业务的网上办理工作量 柱状图 CX_WSBSQKHZ
 * @since 2018-10-16 16:33
 */
@Service
public class Query21Service extends BaseService {

    @Autowired
    @Qualifier("fifthJdbcTemplate")
    private JdbcTemplate fifthJdbcTemplate;

    @Override
    protected JsonResponse invokingService(JsonRequest jsonRequest) {
        return null;
    }


    /**
     * @description 初始化柱图
     * @author Arthur
     * @since 2018-10-16 16:34
     **/
    @SuppressWarnings("SqlDialectInspection")
    public JsonResponse init(JsonRequest jsonRequest) {
        JsonResponse jsonResponse = new JsonResponse();
        UserInfo userInfo = (UserInfo) jsonRequest.getReqData().get("userInfo");
        List<Map<String, Object>> invokeList = fifthJdbcTemplate.queryForList("SELECT T.KYDJ_HS,T.SZRD_HC,T.YSXY_HC,T.KJZDBA_HC,T.BGDJ_HC,T.YBNSRDJ_HC,T.FPGPZGRD_HC,T.ZGKPXEZXXH_HC,T.FPLY_HC,T.FPYJ_HC,T.FPDK_HC,T.ZCSB_HC,T.KQYSSSSBGBTB_HC,T.FPCB_HC,T.FPRZ_HC,T.QT_HC FROM CX_WSBSQKHZ T WHERE T.SWJG_DM = ? ", userInfo.getCxjgDm());
        List<Map<String, Object>> colList = fifthJdbcTemplate.queryForList("SELECT COMMENTS FROM (SELECT T.COLUMN_NAME, T.COMMENTS FROM USER_COL_COMMENTS T WHERE TABLE_NAME = 'CX_WSBSQKHZ') T1 WHERE T1.COLUMN_NAME NOT IN ('SWJG_DM', 'LR_SJ', 'XG_SJ')");
        try {
            jsonResponse.getRepData().put("invoke", StringUtil.getBaseObjectMapper().writeValueAsString(PortalUntil.castMapValue2List(invokeList.get(0))));
            jsonResponse.getRepData().put("xAxis", StringUtil.getBaseObjectMapper().writeValueAsString(colList));
        } catch (JsonProcessingException e) {
           PortalUntil.logger().error("转换 网上办税情况汇总 失败 e : " + e.getMessage());
        }
        return jsonResponse;
    }
}
